{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Example full chip design"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*Make sure to have the right kernel selected!*"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import qiskit_metal as metal\n",
    "from qiskit_metal import designs, draw\n",
    "from qiskit_metal import MetalGUI, Dict, open_docs\n",
    "\n",
    "%metal_heading Welcome to Qiskit Metal!"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Welcome to Qiskit Metal! \n",
    "\n",
    "For this example tutorial, we will attempt to create a multi qubit chip with a variety of components. We will want to generate the layout, simulate/analyze and tune the chip to hit the parameters we are wanting, finally rendering to a GDS file.\n",
    "\n",
    "One could generate subsections of the layout and tune individual components first, but in this case we will create all of the layout. We will be using both transmon pockets and crossmons, meandered and simple transmission lines, capacitive couplers, and launchers for wirebond connections. So we will import these, and also create a design instance and launch the GUI."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Layout"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal.qlibrary.qubits.transmon_pocket_6 import TransmonPocket6\n",
    "from qiskit_metal.qlibrary.qubits.transmon_cross_fl import TransmonCrossFL\n",
    "\n",
    "from qiskit_metal.qlibrary.couplers.tunable_coupler_01 import TunableCoupler01\n",
    "\n",
    "from qiskit_metal.qlibrary.tlines.meandered import RouteMeander\n",
    "from qiskit_metal.qlibrary.tlines.pathfinder import RoutePathfinder\n",
    "from qiskit_metal.qlibrary.tlines.anchored_path import RouteAnchors\n",
    "\n",
    "from qiskit_metal.qlibrary.lumped.cap_n_interdigital import CapNInterdigital\n",
    "from qiskit_metal.qlibrary.couplers.cap_n_interdigital_tee import CapNInterdigitalTee\n",
    "from qiskit_metal.qlibrary.couplers.coupled_line_tee import CoupledLineTee\n",
    "\n",
    "from qiskit_metal.qlibrary.terminations.launchpad_wb import LaunchpadWirebond\n",
    "from qiskit_metal.qlibrary.terminations.launchpad_wb_coupled import LaunchpadWirebondCoupled"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "design = metal.designs.DesignPlanar()\n",
    "\n",
    "gui = metal.MetalGUI(design)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Since we are likely to be making many changes while tuning and modifying our design, we will enable overwriting. We can also check all of the chip properties to see if we want to change the size or any other parameter."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "design.overwrite_enabled = True\n",
    "design.chips.main"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "design.chips.main.size.size_x = '11mm'\n",
    "design.chips.main.size.size_y = '9mm'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### The Qubits"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will add a collection of qubits. First we will place a transmon pocket with six connection pads. We can see any options the qubit qcomponent has to figure out what we might want to modify when creating the component. This will include the components default options (which the component designer included) as well as renderer options (which are added based on what renderers are present in Metal)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "TransmonPocket6.get_template_options(design)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "options =  dict(\n",
    "    pad_width = '425 um', \n",
    "    pocket_height = '650um',\n",
    "    connection_pads=dict(\n",
    "        readout = dict(loc_W=0, loc_H=-1, pad_width = '80um', pad_gap = '50um'),\n",
    "        bus_01 = dict(loc_W=-1, loc_H=-1, pad_width = '60um', pad_gap = '10um'),\n",
    "        bus_02 = dict(loc_W=-1, loc_H=+1, pad_width = '60um', pad_gap = '10um'),\n",
    "        bus_03 = dict(loc_W=0, loc_H=+1, pad_width = '90um', pad_gap = '30um'),\n",
    "        bus_04 = dict(loc_W=+1, loc_H=+1, pad_width = '60um', pad_gap = '10um'),\n",
    "        bus_05 = dict(loc_W=+1, loc_H=-1, pad_width = '60um', pad_gap = '10um')        \n",
    "    ))\n",
    "\n",
    "q_main = TransmonPocket6(design,'Q_Main', options = dict(\n",
    "        pos_x='0mm', \n",
    "        pos_y='-1mm', \n",
    "        gds_cell_name ='FakeJunction_01',\n",
    "        hfss_inductance ='14nH',\n",
    "        **options))\n",
    "\n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then will add a mixture of additional qubits. This is not (though do not let me stop any experimental investigation) a design one would normally create for any experiment of computational purpose, but allows for having a mixture of different components on one chip."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "TransmonCrossFL.get_template_options(design)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We will add two crossmons with flux lines to the west side of the chip, which we will couple to each other using a tunable coupler. To make sure the various readout and control lines will have space to connect to launchers at the chip edge, we have to be mindful of where we place them, and making sure we have enough space for routing while avoiding cross talk."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Q1 = TransmonCrossFL(design, 'Q1', options = dict(pos_x = '-2.75mm', pos_y='-1.8mm',\n",
    "                                                 connection_pads = dict(\n",
    "                                                     bus_01 = dict(connector_location = '180',claw_length ='95um'),\n",
    "                                                     readout = dict(connector_location = '0')),\n",
    "                                                 fl_options = dict()))\n",
    "\n",
    "Q2 = TransmonCrossFL(design, 'Q2', options = dict(pos_x = '-2.75mm', pos_y='-1.2mm', orientation = '180',\n",
    "                                                 connection_pads = dict(\n",
    "                                                     bus_02 = dict(connector_location = '0',claw_length ='95um'),\n",
    "                                                     readout = dict(connector_location = '180')),\n",
    "                                                 fl_options = dict()))\n",
    "\n",
    "\n",
    "tune_c_Q12 = TunableCoupler01(design,'Tune_C_Q12', options = dict(pos_x = '-2.81mm', pos_y = '-1.5mm', \n",
    "                                                                  orientation=90, c_width='500um'))\n",
    "\n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then will add three transmon pockets to the north side of the chip, with the intention of having them in a linear series of coupling to each other, as well as the 'main' qubit to the south."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Q3 = TransmonPocket6(design,'Q3', options = dict(\n",
    "        pos_x='-3mm', \n",
    "        pos_y='0.5mm', \n",
    "        gds_cell_name ='FakeJunction_01',\n",
    "        hfss_inductance ='14nH',\n",
    "        connection_pads = dict(\n",
    "            bus_03 = dict(loc_W=0, loc_H=-1, pad_width = '80um', pad_gap = '15um'),\n",
    "            bus_q3_q4 = dict(loc_W=1, loc_H=-1, pad_width = '80um', pad_gap = '15um'),\n",
    "            readout = dict(loc_W=0, loc_H=1, pad_width = '80um', pad_gap = '50um'))))\n",
    "\n",
    "Q4 = TransmonPocket6(design,'Q4', options = dict(\n",
    "        pos_x='0mm', \n",
    "        pos_y='1mm', \n",
    "        gds_cell_name ='FakeJunction_01',\n",
    "        hfss_inductance ='14nH',\n",
    "        connection_pads = dict(\n",
    "            bus_04 = dict(loc_W=0, loc_H=-1, pad_width = '80um', pad_gap = '15um'),\n",
    "            bus_q3_q4 = dict(loc_W=-1, loc_H=-1, pad_width = '80um', pad_gap = '15um'),\n",
    "            bus_q4_q5 = dict(loc_W=1, loc_H=-1, pad_width = '80um', pad_gap = '15um'),\n",
    "            readout = dict(loc_W=0, loc_H=1, pad_width = '80um', pad_gap = '50um'))))\n",
    "\n",
    "Q5 = TransmonPocket6(design,'Q5', options = dict(\n",
    "        pos_x='3mm', \n",
    "        pos_y='0.5mm', \n",
    "        gds_cell_name ='FakeJunction_01',\n",
    "        hfss_inductance ='14nH',\n",
    "        connection_pads = dict(\n",
    "            bus_05 = dict(loc_W=0, loc_H=-1, pad_width = '80um', pad_gap = '15um'),\n",
    "            bus_q4_q5 = dict(loc_W=-1, loc_H=-1, pad_width = '80um', pad_gap = '15um'),\n",
    "            readout = dict(loc_W=0, loc_H=1, pad_width = '80um', pad_gap = '50um'))))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### The Busses"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We now couple the qubits to each other, primarily using RouteMeander. Although one needs to run simulations to properly tune the line lengths for target frequencies, an initial estimate could be determined from the below method;"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal.analyses.em.cpw_calculations import guided_wavelength\n",
    "\n",
    "def find_resonator_length(frequency, line_width, line_gap, N): \n",
    "    #frequency in GHz\n",
    "    #line_width/line_gap in um\n",
    "    #N -> 2 for lambda/2, 4 for lambda/4\n",
    "    \n",
    "    [lambdaG, etfSqrt, q] = guided_wavelength(frequency*10**9, line_width*10**-6,\n",
    "                                              line_gap*10**-6, 750*10**-6, 200*10**-9)\n",
    "    return str(lambdaG/N*10**3)+\" mm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As we are not worried about a creating a functional chip in this tutorial, we will give the resonators somewhat arbitraty lengths. First coupling the two crossmons to Q_Main."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "bus_01 = RouteMeander(design,'Bus_01', options = dict(hfss_wire_bonds = True, \n",
    "                                            pin_inputs=Dict(\n",
    "                                                start_pin=Dict(\n",
    "                                                    component='Q_Main',\n",
    "                                                    pin='bus_01'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Q1',\n",
    "                                                    pin='bus_01')\n",
    "                                            ),\n",
    "                                            lead=Dict(\n",
    "                                                start_straight='125um',\n",
    "                                                end_straight = '225um'\n",
    "                                            ),\n",
    "                                            meander=Dict(\n",
    "                                                asymmetry = '1305um'),\n",
    "                                            fillet = \"99um\",\n",
    "                                            total_length = '6mm'))\n",
    "\n",
    "bus_02 = RouteMeander(design,'Bus_02', options = dict(hfss_wire_bonds = True, \n",
    "                                            pin_inputs=Dict(\n",
    "                                                start_pin=Dict(\n",
    "                                                    component='Q_Main',\n",
    "                                                    pin='bus_02'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Q2',\n",
    "                                                    pin='bus_02')\n",
    "                                            ),\n",
    "                                            lead=Dict(\n",
    "                                                start_straight='325um',\n",
    "                                                end_straight = '125um'\n",
    "                                            ),\n",
    "                                            meander=Dict(\n",
    "                                                asymmetry = '450um'),\n",
    "                                            fillet = \"99um\",\n",
    "                                            total_length = '6.4mm'))\n",
    "\n",
    "\n",
    "gui.rebuild()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Then the three transmon pockets on the north side to Q_Main."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "bus_03 = RouteMeander(design,'Bus_03', options = dict(hfss_wire_bonds = True, \n",
    "                                            pin_inputs=Dict(\n",
    "                                                start_pin=Dict(\n",
    "                                                    component='Q_Main',\n",
    "                                                    pin='bus_03'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Q3',\n",
    "                                                    pin='bus_03')\n",
    "                                            ),\n",
    "                                            lead=Dict(\n",
    "                                                start_straight='225um',\n",
    "                                                end_straight = '25um'\n",
    "                                            ),\n",
    "                                            meander=Dict(\n",
    "                                                asymmetry = '50um'),\n",
    "                                            fillet = \"99um\",\n",
    "                                            total_length = '6.8mm'))\n",
    "\n",
    "#To help set the right spacing, jogs can be used to set some initially controlled routing paths\n",
    "from collections import OrderedDict\n",
    "jogs_start = OrderedDict()\n",
    "jogs_start[0] = [\"L\", '250um']\n",
    "jogs_start[1] = [\"R\", '200um']\n",
    "\n",
    "jogs_end = OrderedDict()\n",
    "jogs_end[0] = [\"L\", '600um']\n",
    "\n",
    "bus_04 = RouteMeander(design,'Bus_04', options = dict(hfss_wire_bonds = True, \n",
    "                                            pin_inputs=Dict(\n",
    "                                                start_pin=Dict(\n",
    "                                                    component='Q_Main',\n",
    "                                                    pin='bus_04'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Q4',\n",
    "                                                    pin='bus_04')\n",
    "                                            ),\n",
    "                                            lead=Dict(\n",
    "                                                start_straight='225um',\n",
    "                                                #end_straight = '25um',\n",
    "                                                start_jogged_extension=jogs_start,\n",
    "                                                #end_jogged_extension = jogs_end\n",
    "                                            ),\n",
    "                                            meander=Dict(\n",
    "                                                asymmetry = '150um'),\n",
    "                                            fillet = \"99um\",\n",
    "                                            total_length = '7.2mm'))\n",
    "\n",
    "bus_05 = RouteMeander(design,'Bus_05', options = dict(hfss_wire_bonds = True, \n",
    "                                            pin_inputs=Dict(\n",
    "                                                start_pin=Dict(\n",
    "                                                    component='Q_Main',\n",
    "                                                    pin='bus_05'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Q5',\n",
    "                                                    pin='bus_05')\n",
    "                                            ),\n",
    "                                            lead=Dict(\n",
    "                                                start_straight='225um',\n",
    "                                                end_straight = '25um'\n",
    "                                            ),\n",
    "                                            meander=Dict(\n",
    "                                                asymmetry = '50um'),\n",
    "                                            fillet = \"99um\",\n",
    "                                            total_length = '7.6mm'))\n",
    "\n",
    "gui.rebuild()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finally the three transmon pockets on the north side to each other. This concludes the interconnectivity between the qubits."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "bus_q3_q4 = RouteMeander(design,'Bus_Q3_Q4', options = dict(hfss_wire_bonds = True, \n",
    "                                            pin_inputs=Dict(\n",
    "                                                start_pin=Dict(\n",
    "                                                    component='Q3',\n",
    "                                                    pin='bus_q3_q4'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Q4',\n",
    "                                                    pin='bus_q3_q4')\n",
    "                                            ),\n",
    "                                            lead=Dict(\n",
    "                                                start_straight='125um',\n",
    "                                                end_straight = '125um'\n",
    "                                            ),\n",
    "                                            meander=Dict(\n",
    "                                                asymmetry = '50um'),\n",
    "                                            fillet = \"99um\",\n",
    "                                            total_length = '6.4mm'))\n",
    "\n",
    "bus_q4_q5 = RouteMeander(design,'Bus_Q4_Q5', options = dict(hfss_wire_bonds = True, \n",
    "                                            pin_inputs=Dict(\n",
    "                                                start_pin=Dict(\n",
    "                                                    component='Q4',\n",
    "                                                    pin='bus_q4_q5'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Q5',\n",
    "                                                    pin='bus_q4_q5')\n",
    "                                            ),\n",
    "                                            lead=Dict(\n",
    "                                                start_straight='125um',\n",
    "                                                end_straight = '25um'\n",
    "                                            ),\n",
    "                                            meander=Dict(\n",
    "                                                asymmetry = '50um'),\n",
    "                                            fillet = \"99um\",\n",
    "                                            total_length = '6.8mm'))\n",
    "\n",
    "gui.rebuild()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### The Readouts and Control Lines\n",
    "\n",
    "The intention for this design is to have the three north transmon pockets be multiplexed to one readout line. The crossmons to their own readouts, as well as Q_Main. The tunable coupler, and the two crossmons also have flux lines which need to be connected to launchers.\n",
    "First we will place the wirebond launchers at the edges of the chip."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "launch_qmain_read = LaunchpadWirebond(design, 'Launch_QMain_Read', options = dict(pos_x = '2mm', pos_y ='-4mm', orientation = '90'))\n",
    "\n",
    "launch_q1_fl = LaunchpadWirebond(design, 'Launch_Q1_FL', options = dict(pos_x = '0mm', pos_y ='-4mm', orientation = '90', \n",
    "                                                                        trace_width = '5um',\n",
    "                                                                        trace_gap = '3um',))\n",
    "launch_q1_read = LaunchpadWirebondCoupled(design, 'Launch_Q1_Read', options = dict(pos_x = '-2mm', pos_y ='-4mm', orientation = '90'))\n",
    "\n",
    "launch_tcoup_fl = LaunchpadWirebond(design, 'Launch_TuneC_FL', options = dict(pos_x = '-4mm', pos_y ='-4mm', orientation = '90',\n",
    "                                                                             trace_width = '5um',\n",
    "                                                                             trace_gap = '3um',))\n",
    "launch_tcoup_read = LaunchpadWirebondCoupled(design, 'Launch_TuneC_Read', options = dict(pos_x = '-5mm', pos_y ='-3mm', orientation = '0'))\n",
    "\n",
    "launch_q2_read = LaunchpadWirebondCoupled(design, 'Launch_Q2_Read', options = dict(pos_x = '-5mm', pos_y ='-1mm', orientation = '0'))\n",
    "launch_q2_fl = LaunchpadWirebond(design, 'Launch_Q2_FL', options = dict(pos_x = '-5mm', pos_y ='1mm', orientation = '0',\n",
    "                                                                       trace_width = '5um',\n",
    "                                                                        trace_gap = '3um',))\n",
    "\n",
    "launch_nw = LaunchpadWirebond(design, 'Launch_NW',options = dict(pos_x = '-5mm', pos_y='3mm', orientation=0))\n",
    "launch_ne = LaunchpadWirebond(design, 'Launch_NE',options = dict(pos_x = '5mm', pos_y='3mm', orientation=180))\n",
    "\n",
    "\n",
    "gui.rebuild()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We then will add in the readout resonators for Q_Main, Q1, Q2 and the tuneable coupler.\n",
    "We will add a finger capacitor for the Q_Main readout, instead of just using the LaunchpadWirebondCoupled."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Main Readout\n",
    "\n",
    "\n",
    "read_q_main_cap = CapNInterdigital(design,'Read_Q_Main_Cap', options = dict(pos_x = '2mm', pos_y ='-3.5mm', orientation = '0'))\n",
    "\n",
    "jogs_end = OrderedDict()\n",
    "jogs_end[0] = [\"L\", '600um']\n",
    "\n",
    "jogs_start = OrderedDict()\n",
    "jogs_start[0] = [\"L\", '250um']\n",
    "\n",
    "read_q_main = RouteMeander(design,'Read_Q_Main', options = dict(hfss_wire_bonds = True, \n",
    "                                            pin_inputs=Dict(\n",
    "                                                start_pin=Dict(\n",
    "                                                    component='Q_Main',\n",
    "                                                    pin='readout'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Read_Q_Main_Cap',\n",
    "                                                    pin='north_end')\n",
    "                                            ),\n",
    "                                            lead=Dict(\n",
    "                                                start_straight='725um',\n",
    "                                                end_straight = '625um',\n",
    "                                                start_jogged_extension = jogs_start,\n",
    "                                                end_jogged_extension = jogs_end\n",
    "                                            ),\n",
    "                                            meander=Dict(\n",
    "                                                asymmetry = '50um'),\n",
    "                                            fillet = \"99um\",\n",
    "                                            total_length = '5.6mm'))\n",
    "\n",
    "read_q_main_cap_launch = RoutePathfinder(design, 'Read_Q_Main_Cap_Launch', options = dict(hfss_wire_bonds = True,\n",
    "                                                    pin_inputs = dict(\n",
    "                                                        start_pin=Dict(\n",
    "                                                    component='Read_Q_Main_Cap',\n",
    "                                                    pin='south_end'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Launch_QMain_Read',\n",
    "                                                    pin='tie')),\n",
    "                                                lead=Dict(\n",
    "                                                start_straight='0um',\n",
    "                                                end_straight = '0um',\n",
    "                                                #start_jogged_extension = jogs_start,\n",
    "                                                #end_jogged_extension = jogs_end\n",
    "                                            )))\n",
    "    \n",
    "\n",
    "\n",
    "gui.rebuild()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Crossmon's Readouts\n",
    "\n",
    "jogs_end = OrderedDict()\n",
    "jogs_end[0] = [\"L\", '600um']\n",
    "\n",
    "jogs_start = OrderedDict()\n",
    "jogs_start[0] = [\"L\", '250um']\n",
    "\n",
    "read_q1 = RouteMeander(design,'Read_Q1', options = dict(hfss_wire_bonds = True, \n",
    "                                            pin_inputs=Dict(\n",
    "                                                start_pin=Dict(\n",
    "                                                    component='Q1',\n",
    "                                                    pin='readout'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Launch_Q1_Read',\n",
    "                                                    pin='tie')\n",
    "                                            ),\n",
    "                                            lead=Dict(\n",
    "                                                start_straight='250um',\n",
    "                                                end_straight = '25um',\n",
    "                                                #start_jogged_extension = jogs_start,\n",
    "                                                #end_jogged_extension = jogs_end\n",
    "                                            ),\n",
    "                                            meander=Dict(\n",
    "                                                asymmetry = '50um'),\n",
    "                                            fillet = \"99um\",\n",
    "                                            total_length = '6.8mm'))\n",
    "\n",
    "\n",
    "jogs_end = OrderedDict()\n",
    "jogs_end[0] = [\"L\", '600um']\n",
    "\n",
    "jogs_start = OrderedDict()\n",
    "jogs_start[0] = [\"L\", '250um']\n",
    "\n",
    "read_tunec = RouteMeander(design,'Read_TuneC', options = dict(hfss_wire_bonds = True, \n",
    "                                            pin_inputs=Dict(\n",
    "                                                start_pin=Dict(\n",
    "                                                    component='Tune_C_Q12',\n",
    "                                                    pin='Control'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Launch_TuneC_Read',\n",
    "                                                    pin='tie')\n",
    "                                            ),\n",
    "                                            lead=Dict(\n",
    "                                                start_straight='1525um',\n",
    "                                                end_straight = '125um',\n",
    "                                                #start_jogged_extension = jogs_start,\n",
    "                                                #end_jogged_extension = jogs_end\n",
    "                                            ),\n",
    "                                            meander=Dict(\n",
    "                                                asymmetry = '50um'),\n",
    "                                            fillet = \"99um\",\n",
    "                                            total_length = '5.8mm'))\n",
    "\n",
    "jogs_end = OrderedDict()\n",
    "jogs_end[0] = [\"L\", '600um']\n",
    "\n",
    "jogs_start = OrderedDict()\n",
    "jogs_start[0] = [\"L\", '250um']\n",
    "\n",
    "\n",
    "\n",
    "read_q2 = RouteMeander(design,'Read_Q2', options = dict(hfss_wire_bonds = True, \n",
    "                                            pin_inputs=Dict(\n",
    "                                                start_pin=Dict(\n",
    "                                                    component='Q2',\n",
    "                                                    pin='readout'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Launch_Q2_Read',\n",
    "                                                    pin='tie')\n",
    "                                            ),\n",
    "                                            lead=Dict(\n",
    "                                                start_straight='350um',\n",
    "                                                end_straight = '0um',\n",
    "                                                #start_jogged_extension = jogs_start,\n",
    "                                                #end_jogged_extension = jogs_end\n",
    "                                            ),\n",
    "                                            meander=Dict(\n",
    "                                                asymmetry = '-450um'),\n",
    "                                            fillet = \"99um\",\n",
    "                                            total_length = '5.4mm'))\n",
    "\n",
    "\n",
    "gui.rebuild()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finishing off this section of the chip by connecting the flux lines to appropraite wirebond launch pads."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Crossmon flux lines\n",
    "\n",
    "flux_line_Q1 = RoutePathfinder(design,'Flux_Line_Q1', options = dict(hfss_wire_bonds = True,\n",
    "                                            pin_inputs=Dict(\n",
    "                                                start_pin=Dict(\n",
    "                                                    component='Q1',\n",
    "                                                    pin='flux_line'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Launch_Q1_FL',\n",
    "                                                    pin='tie')),\n",
    "                                            fillet = '99um',\n",
    "                                            trace_width = '5um',\n",
    "                                            trace_gap = '3um',\n",
    "                                            #anchors = anchors\n",
    "                                            ))\n",
    "\n",
    "\n",
    "jogs_start = OrderedDict()\n",
    "jogs_start[0] = [\"L\", '750um']\n",
    "\n",
    "flux_line_tunec = RoutePathfinder(design,'Flux_Line_TuneC', options = dict(hfss_wire_bonds = True,\n",
    "                                            pin_inputs=Dict(\n",
    "                                                start_pin=Dict(\n",
    "                                                    component='Tune_C_Q12',\n",
    "                                                    pin='Flux'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Launch_TuneC_FL',\n",
    "                                                    pin='tie')),\n",
    "                                            lead=Dict(\n",
    "                                                start_straight='875um',\n",
    "                                                end_straight = '350um',\n",
    "                                                start_jogged_extension = jogs_start,\n",
    "                                                #end_jogged_extension = jogs_end\n",
    "                                            ),\n",
    "                                            fillet = '99um',\n",
    "                                            trace_width = '5um',\n",
    "                                            trace_gap = '3um',\n",
    "                                            #anchors = anchors\n",
    "                                            ))\n",
    "\n",
    "\n",
    "jogs_start = OrderedDict()\n",
    "jogs_start[0] = [\"L\", '525um']\n",
    "jogs_start[1] = [\"R\", '625um']\n",
    "\n",
    "flux_line_Q2 = RoutePathfinder(design,'Flux_Line_Q2', options = dict(hfss_wire_bonds = True,\n",
    "                                            pin_inputs=Dict(\n",
    "                                                start_pin=Dict(\n",
    "                                                    component='Q2',\n",
    "                                                    pin='flux_line'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Launch_Q2_FL',\n",
    "                                                    pin='tie')),\n",
    "                                            lead=Dict(\n",
    "                                                start_straight='175um',\n",
    "                                                end_straight = '150um',\n",
    "                                                start_jogged_extension = jogs_start,\n",
    "                                                #end_jogged_extension = jogs_end\n",
    "                                            ),\n",
    "                                            fillet = '99um',\n",
    "                                            trace_width = '5um',\n",
    "                                            trace_gap = '3um',\n",
    "                                            #anchors = anchors\n",
    "                                            ))\n",
    "\n",
    "gui.rebuild()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Shifting our focus now to the three transmon pockets in the north. As we want these to be multiplexed to a single readout line, we will add in a few three port components, such as the CoupledLineTee and CapNInterdigitalTee.\n",
    "Q3 will have an inductive coupling to the readout line (as we want a lambda/4 resonator), Q4 will have a simple gap capacitor, and Q5 will have an interdigitated capacitor."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "q3_read_T = CoupledLineTee(design,'Q3_Read_T', options=dict(pos_x = '-3mm', pos_y = '3mm', \n",
    "                                                        orientation = '0', \n",
    "                                                        coupling_length = '200um',\n",
    "                                                        open_termination = False))\n",
    "#We use finger count to set the width of the gap capacitance, -> N*cap_width + (N-1)*cap_gap\n",
    "q4_read_T = CapNInterdigitalTee(design,'Q4_Read_T', options=dict(pos_x = '0mm', pos_y = '3mm', \n",
    "                                                           orientation = '0', \n",
    "                                                           finger_length = '0um', \n",
    "                                                           finger_count = '8'))\n",
    "q5_read_T = CapNInterdigitalTee(design,'Q5_Read_T', options=dict(pos_x = '3mm', pos_y = '3mm', \n",
    "                                                           orientation = '0', \n",
    "                                                           finger_length = '50um', \n",
    "                                                           finger_count = '11'))\n",
    "\n",
    "gui.rebuild()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We add in the readout resonators to each respective qubit."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "read_q3 = RouteMeander(design,'Read_Q3', options = dict(hfss_wire_bonds = True, \n",
    "                                            pin_inputs=Dict(\n",
    "                                                start_pin=Dict(\n",
    "                                                    component='Q3',\n",
    "                                                    pin='readout'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Q3_Read_T',\n",
    "                                                    pin='second_end')\n",
    "                                            ),\n",
    "                                            lead=Dict(\n",
    "                                                start_straight='150um',\n",
    "                                                end_straight = '150um',\n",
    "                                                #start_jogged_extension = jogs_start,\n",
    "                                                #end_jogged_extension = jogs_end\n",
    "                                            ),\n",
    "                                            meander=Dict(\n",
    "                                                asymmetry = '0um'),\n",
    "                                            fillet = \"99um\",\n",
    "                                            total_length = '5mm'))\n",
    "\n",
    "read_q4 = RouteMeander(design,'Read_Q4', options = dict(hfss_wire_bonds = True, \n",
    "                                            pin_inputs=Dict(\n",
    "                                                start_pin=Dict(\n",
    "                                                    component='Q4',\n",
    "                                                    pin='readout'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Q4_Read_T',\n",
    "                                                    pin='second_end')\n",
    "                                            ),\n",
    "                                            lead=Dict(\n",
    "                                                start_straight='125um',\n",
    "                                                end_straight = '125um',\n",
    "                                                #start_jogged_extension = jogs_start,\n",
    "                                                #end_jogged_extension = jogs_end\n",
    "                                            ),\n",
    "                                            meander=Dict(\n",
    "                                                asymmetry = '0um'),\n",
    "                                            fillet = \"99um\",\n",
    "                                            total_length = '5.8mm'))\n",
    "\n",
    "read_q5 = RouteMeander(design,'Read_Q5', options = dict(hfss_wire_bonds = True, \n",
    "                                            pin_inputs=Dict(\n",
    "                                                start_pin=Dict(\n",
    "                                                    component='Q5',\n",
    "                                                    pin='readout'),\n",
    "                                                end_pin=Dict(\n",
    "                                                    component='Q5_Read_T',\n",
    "                                                    pin='second_end')\n",
    "                                            ),\n",
    "                                            lead=Dict(\n",
    "                                                start_straight='125um',\n",
    "                                                end_straight = '125um',\n",
    "                                                #start_jogged_extension = jogs_start,\n",
    "                                                #end_jogged_extension = jogs_end\n",
    "                                            ),\n",
    "                                            meander=Dict(\n",
    "                                                asymmetry = '0um'),\n",
    "                                            fillet = \"99um\",\n",
    "                                            total_length = '5.4mm'))\n",
    "\n",
    "gui.rebuild()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We complete the layout by connecting the multiplexed readout line to the launchpads on either side of the chip."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "mp_tl_01 = RoutePathfinder(design, 'ML_TL_01', options = dict(hfss_wire_bonds = True,\n",
    "                                                    pin_inputs = dict(\n",
    "                                                    start_pin=Dict(\n",
    "                                                        component='Launch_NW',\n",
    "                                                        pin='tie'),\n",
    "                                                    end_pin=Dict(\n",
    "                                                        component='Q3_Read_T',\n",
    "                                                        pin='prime_start'))\n",
    "                                            ))\n",
    "\n",
    "mp_tl_02 = RoutePathfinder(design, 'ML_TL_02', options = dict(hfss_wire_bonds = True,\n",
    "                                                    pin_inputs = dict(\n",
    "                                                    start_pin=Dict(\n",
    "                                                        component='Q3_Read_T',\n",
    "                                                        pin='prime_end'),\n",
    "                                                    end_pin=Dict(\n",
    "                                                        component='Q4_Read_T',\n",
    "                                                        pin='prime_start'))\n",
    "                                            ))\n",
    "\n",
    "mp_tl_03 = RoutePathfinder(design, 'ML_TL_03', options = dict(hfss_wire_bonds = True,\n",
    "                                                    pin_inputs = dict(\n",
    "                                                    start_pin=Dict(\n",
    "                                                        component='Q4_Read_T',\n",
    "                                                        pin='prime_end'),\n",
    "                                                    end_pin=Dict(\n",
    "                                                        component='Q5_Read_T',\n",
    "                                                        pin='prime_start'))\n",
    "                                            ))\n",
    "\n",
    "mp_tl_04 = RoutePathfinder(design, 'ML_TL_04', options = dict(hfss_wire_bonds = True,\n",
    "                                                    pin_inputs = dict(\n",
    "                                                    start_pin=Dict(\n",
    "                                                        component='Q5_Read_T',\n",
    "                                                        pin='prime_end'),\n",
    "                                                    end_pin=Dict(\n",
    "                                                        component='Launch_NE',\n",
    "                                                        pin='tie'))\n",
    "                                            ))\n",
    "\n",
    "gui.rebuild()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With this, we have completed the construction of our layout. \n",
    "\n",
    "Now, anyone familiar with chip design might find some of the location choices to be sub-optimal, with large sections of your chip left unused, or perhaps some CPW transmission lines running a bit closer to each other than would be ideal for avoiding cross talk concerns. These could be address by shifting the origin of your chip, or modifying component options to better compact your layout and alleviate crosstalk concerns.\n",
    "\n",
    "For this tutorial, we aren't too concerned how much space we may use up on our fictional chip, so we will instead continue on to analysis and tuning."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Analyze\n",
    "## Capacitance Extraction and LOM"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "First we want to quickly look at the qubit parameters. Initial simulation and analysis is to use a lumped element approximation, by extracting the capacitance matrix of the qubit. We first analyze the qubit `Q_Main`, by first extracting the matrix and then using LOM analysis on it.\n",
    "\n",
    "For starters, let's select the appropriate QAnalysis class."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal.analyses.quantization import LOManalysis\n",
    "c1 = LOManalysis(design, \"q3d\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can check if we wish to change any of the default options for the analysis. You should modify the number of passes and convergence based on the accuracy you require for your simulation.\n",
    "\n",
    "Depending on the complexity of the simulation, it could take a minute, or multiple hours. It is generally best to start with a small number of `max_passes` if you are unsure, so can you get a sense on the timing. As each adaptive pass adds additional tetrahedrons, the simulation time per pass will increase significantly (as well as the amount of system memory necessary)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "c1.sim.setup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "c1.sim.setup.name = 'Tune_Q_Main'\n",
    "c1.sim.setup.max_passes = 16\n",
    "c1.sim.setup.min_converged_passes = 2\n",
    "c1.sim.setup.percent_error = 0.05\n",
    "c1.sim.setup"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next we will want to run the simulation for Q_Main. To obtain the complete capacitance matrix from this simulation, we will want to terminate the unconnected pins of Q_Main with opens, so that they are regarded as isolated charge islands in the simulation. You will need to list all of the pin names in the call. To recall them, one can look at the GUI, or check the pin dictionary attached to Q_Main: `q_main.pins.keys()`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "c1.sim.run(name=\"Q_Main\", components=['Q_Main'], open_terminations=[('Q_Main', 'readout'), ('Q_Main', 'bus_01'),('Q_Main', 'bus_02'),('Q_Main', 'bus_03'),\n",
    "                                      ('Q_Main', 'bus_04'), ('Q_Main', 'bus_05')])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With the simulation completed, we can look at the capacitance matrix."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "c1.sim.capacitance_matrix"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "But more importantly, we can use that matrix to run LOM analysis."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "c1.setup.junctions = Dict({'Lj': 14, 'Cj': 2})\n",
    "c1.setup.freq_readout = 7.0\n",
    "c1.setup.freq_bus = [5.6, 5.7, 5.8, 5.9, 6.0]  # list of the bus frequencies\n",
    "\n",
    "c1.run_lom()\n",
    "c1.lumped_oscillator_all"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Which gives us the qubits frequency, anharmonicity, and coupling strength to the different connection pads.\n",
    "\n",
    "We can further check if these parameters converged well. If they have not, we may want to modify our simulation in order to get a more accurate result. We then will want to make modifications to our qubit options, such as `pad_gap` of the qubit, or modifying the size of the connection pads, in order to hit the desired qubit anharmonicity or readout chi values respectively."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "c1.plot_convergence();\n",
    "c1.plot_convergence_chi()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Once the analysis and tuning is complete, we can stop the analysis and the renderer."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "c1.sim.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Eigenmode and EPR\n",
    "\n",
    "Once each of our qubits have been run through LOM, we can begin to look at the resonant busses and readouts, and larger coupled sections of the chip. One such case could be looking at Q_Main, Q5, and Bus_05. This allows us not only to look at some of the parameters of the individual qubits, but also the bus frequency and if the qubits are coupled (via the bus) to the degree we wish.\n",
    "\n",
    "#### Preparations\n",
    "We will setup the design and simulation in the same manner as we did previously, but with the methods needed for an eigenmode simulation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal.analyses.quantization import EPRanalysis\n",
    "eig_qb = EPRanalysis(design, \"hfss\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "(optional) you can tune the wirebond size by directly modifying the renderer options."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "eig_qb.sim.renderer.options['wb_size'] = 5"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Review and update the simulation setup by executing following two cells."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "em_p = eig_qb.sim.setup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "em_p.name = '3Modes'\n",
    "em_p.min_freq_ghz = 4\n",
    "em_p.n_modes = 3\n",
    "em_p.max_passes = 10\n",
    "em_p.max_delta_f = 0.1\n",
    "em_p.min_converged = 2\n",
    "# Design variables can also be added in for direct simulation sweeps.\n",
    "em_p.vars = Dict({'Lj1': '13 nH', 'Cj1': '0 fF', 'Lj2': '15 nH', 'Cj2': '0 fF'})\n",
    "\n",
    "eig_qb.sim.setup"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Before we execute the analysis, we want to update the design if needed. For example we may want to modify the junction inductance of the two qubits based on the previous LOM analysis, so they are near the desired frequency. Further, one may want to change the length of the bus after initial simulations to get it to the target frequency:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "q_main.options.hfss_inductance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "Q5.options.hfss_inductance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "q_main.options.hfss_inductance = '13nH'\n",
    "Q5.options.hfss_inductance = '15nH'\n",
    "bus_05.options.total_length = '7.5mm'\n",
    "\n",
    "gui.rebuild()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can now run the simulation on the specified layout. All unconnected pins are left as shorts, as we are only concerned about simulating the resonant mode of the three components listed."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "eig_qb.sim.run(name=\"QMain_Q5_Bus05\", components=['Q_Main', 'Q5','Bus_05'], open_terminations=[])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Once the simulation is complete, we can check to see if the convergence was good."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "eig_qb.sim.plot_convergences()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With the eigenmode simulation complete (and nicely converged) we can run some EPR analysis on the result.\n",
    "\n",
    "At first we need to define the junctions in terms of name, inductance_variable, capacitance_variable, rectancle that was defined in the rendering to represent the junction `port` and line that was defined in the rendering to represent the direction of the current thorugh the junction."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "eig_qb.del_junction()\n",
    "eig_qb.add_junction('jj1', 'Lj1', 'Cj1', rect='JJ_rect_Lj_Q_Main_rect_jj', line='JJ_Lj_Q_Main_rect_jj_')\n",
    "eig_qb.add_junction('jj2', 'Lj2', 'Cj2', rect='JJ_rect_Lj_Q5_rect_jj', line='JJ_Lj_Q5_rect_jj_')\n",
    "eig_qb.setup.sweep_variable = 'Lj1'\n",
    "eig_qb.setup"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Note in the previous cell output that the dissipatives have alrady been defined by default.\n",
    "\n",
    "Now we can start looking at the EPR values. First we look at the electric field and subtrate participation. Then extract the kerr matrix."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "eig_qb.run_epr()\n",
    "# (pyEPR allows to switch modes: eprd.set_mode(1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "From the analysis results we can determine the qubits anharmonicities and coupling strength.\n",
    "Once the analysis and tuning is complete, we can close the connection to Ansys."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "eig_qb.sim.close()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Rendering to a GDS File"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Once all of the tuning is complete, we will want to prepare a GDS file so we can create a mask and fabricate our chip. We first create a gds render instance."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "full_chip_gds = design.renderers.gds"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The various options for the gds renderer can also be checked and changed as necessary. A key option is the gds file which holds the cells for your junction ebeam design. Make sure this is pointing at the correct file so they are placed in your final mask at the appropriate locations."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "full_chip_gds.options"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "full_chip_gds.options['path_filename'] ='../resources/Fake_Junctions.GDS'\n",
    "full_chip_gds.options['no_cheese']['buffer']='50um'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "full_chip_gds.export_to_gds('Full_Chip_01.gds')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "(optional) With the design complete, we can close the GUI."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# gui.main_window.close()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
